#include<reg52.h>
#define LED P2
#define uchar unsigned char
sbit beep=P3^7;              //蜂鸣器
void delay(int ms);
int count1=0,flag=1,flag2=0;//中断计数、闪烁方式标志
void main()
{
	 int i=0,j=0;
	 uchar a=1,b=1;
	 TMOD=0X01;
	 TH0=(65536-50000)/256;
	 TL0=(65536-50000)%256;
	 EA=1;ET0=1;TR0=1;
	 LED=0X00;
   while(1)
	 {
	    beep=0;            //蜂鸣器报警
		  delay(500);
		 for(j=0;j<100;j++)
		 {
		   beep=0;delay(1);
			 beep=1;delay(5);
		 }
	 }
}


void delay(int ms)
{
    int x,y;
   for(x=ms;x>0;x--)
      for(y=123;y>0;y--); 
}

void timer0() interrupt 1
{
   TH0=(65536-50000)/256;
	 TL0=(65536-50000)%256;
	 count1++;
	 if(flag==1)             //绿灯黄灯亮
	 {
	   	count1=0;
			LED=0X18;
			flag=2;
   }	 
	 if(flag==2)             //红灯亮
	 {
	   if(count1==20)     
	  {
			count1=0;
			LED=0XE7;
			count1=0;
			flag=3;
	  }
   }	
	 if(flag==3)              //闪烁
	 {	
   		if(flag2==1||count1==20)
			{				
			  LED=~LED;
				flag2=1;
		    if(count1==40)
		    {  flag=1;count1=0;flag2=0;   }
				
	    }		 
   }	 
}